package com.szosen.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import android.content.Intent;

import com.szosen.json.PastHistorylist;
import com.szosen.util.JibingContants.BM.CJZK;

public class JibingContants {
	/***
	 * 根据类型获取药物过敏史、手术史、输血史？这些类别。
	 * 
	 * @return
	 */
	public static List<PastHistorylist> getPastHistorylistsByType(
			List<PastHistorylist> list, Class type) {
		List<PastHistorylist> result = new ArrayList<PastHistorylist>();
		for (int i = 0; i < list.size(); i++) {
			PastHistorylist bean = list.get(i);
			String code0 = bean.getPastHisTypeCode();
//			bean.getDiseaseText()
			if (getCodeByclass(type).equals(code0)) {
				result.add(bean);
			}
		}
		return result;
	}

	private static String getCodeByclass(Class type) {
		if (type == JibingContants.BM.YWGMS.class) {
			return "01";
		}
		if (type == JibingContants.BM.JBS.class) {
			return "02";
		}
		if (type == JibingContants.BM.SSS.class) {
			return "03";
		}
		if (type == JibingContants.BM.SXS.class) {
			return "04";
		}
		if (type == JibingContants.BM.YCBS.class) {
			return "05";
		}
		if (type == JibingContants.BM.WSS.class) {
			return "06";
		}
		if (type == JibingContants.BM.JZJBS_FQ.class) {
			return "07";
		}
		if (type == JibingContants.BM.JZJBS_MQ.class) {
			return "08";
		}
		if (type == JibingContants.BM.JZJBS_XDJM.class) {
			return "09";
		}
		if (type == JibingContants.BM.JZJBS_ZN.class) {
			return "10";
		}
		if (type == JibingContants.BM.CJZK.class) {
			return "11";
		}
		if (type == JibingContants.BM.BLS.class) {
			return "12";
		}
		return "";
	}

	public static List<String[]> getArrayByCode(List<PastHistorylist> list) {
		List<String[]> result = new ArrayList<String[]>();
		if (list == null || list.size() == 0) {
			return result;
		}
		for (int i = 0; i < list.size(); i++) {
			PastHistorylist bean = list.get(i);
			String code0 = bean.getPastHisTypeCode();
			String code1 = bean.getDiseaseCode();
			String code2 = bean.getMethodsCode();
			String code3 = bean.getVestingCode();
			String data0 = getStringByJWSLB(code0);
			String data1 = getStringByBM(code0, code1);
			String data2 = getStringByGCFF(code2);
			String data3 = getStringByZGQK(code3);
			result.add(new String[] { data0, data1, data2, data3 });
		}
		return result;
	}

	/***
	 * 既往史类别
	 * 
	 * @author geshenjibi
	 * 
	 */
	public static class JWSLB {
		public static final String[] names = new String[] { "药物过敏史", "疾病史",
				"手术史", "输血史", "遗传病史", "外伤史", "家族疾病史-父亲", "家族疾病史-母亲",
				"家族疾病史-兄弟姐妹", "家族疾病史-子女", "残疾状况" };

		public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
		static {
			map.put("01", "药物过敏史");
			map.put("02", "疾病史");
			map.put("03", "手术史");
			map.put("04", "输血史");
			map.put("05", "遗传病史");
			map.put("06", "外伤史");
			map.put("07", "家族疾病史-父亲");
			map.put("08", "家族疾病史-母亲");
			map.put("09", "家族疾病史-兄弟姐妹");
			map.put("10", "家族疾病史-子女");
			map.put("11", "残疾状况");
			map.put("12", "暴露史");
		}
	}

	/**
	 * 观测方法的code
	 * */
	public static String getCodeByGCFF(String gcff) {
		return getKeyByValue(GCFF.map, gcff);
	}

	/**
	 * 残疾状况的code
	 * */
	public static String getCodeByCJZK(String cjzk) {
		return getKeyByValue(CJZK.map, cjzk);
	}

	/**
	 * 转归情况的code
	 * */
	public static String getCodeByZGQK(String zgqk) {
		return getKeyByValue(ZGQK.map, zgqk);
	}

	/**
	 * 既往史类别的code
	 * */
	public static String getCodeByJWSLB(String jwslb) {
		return getKeyByValue(JWSLB.map, jwslb);
	}

	/**
	 * 观测方法的code
	 * */
	public static String getStringByGCFF(String gcffCode) {
		return getValueByKey(GCFF.map, gcffCode);
	}

	/**
	 * 残疾状况的code
	 * */
	public static String getStringByCJZK(String cjzkCode) {
		return getValueByKey(CJZK.map, cjzkCode);
	}

	/**
	 * 转归情况的code
	 * */
	public static String getStringByZGQK(String zgqkCode) {
		return getValueByKey(ZGQK.map, zgqkCode);
	}

	/**
	 * 既往史类别的code
	 * */
	public static String getStringByJWSLB(String jwslbCode) {
		return getValueByKey(JWSLB.map, jwslbCode);
	}

	/**
	 * 既往史类别的code
	 * */
	public static String getCodeByBM(String jwslb, String bm) {
		switch (jwslb) {
		case "药物过敏史":
			return getKeyByValue(BM.YWGMS.map, bm);
		case "疾病史":
			return getKeyByValue(BM.JBS.map, bm);
		case "手术史":
			return getKeyByValue(BM.SSS.map, bm);
		case "输血史":
			return getKeyByValue(BM.SXS.map, bm);
		case "遗传病史":
			return getKeyByValue(BM.YCBS.map, bm);
		case "外伤史":
			return getKeyByValue(BM.WSS.map, bm);
		case "家族疾病史-父亲":
			return getKeyByValue(BM.JZJBS_FQ.map, bm);
		case "家族疾病史-母亲":
			return getKeyByValue(BM.JZJBS_MQ.map, bm);
		case "家族疾病史-兄弟姐妹":
			return getKeyByValue(BM.JZJBS_XDJM.map, bm);
		case "家族疾病史-子女":
			return getKeyByValue(BM.JZJBS_ZN.map, bm);
		case "残疾状况":
			return getKeyByValue(BM.CJZK.map, bm);
		case "暴露史":
			return getKeyByValue(BM.BLS.map, bm);

		default:
			break;
		}
		return "";
	}

	/**
	 * 既往史类别的code
	 * */
	public static String getStringByBM(String jwslbCode, String bmCode) {
		switch (jwslbCode) {
		case "01":
			return getValueByKey(BM.YWGMS.map, bmCode);
		case "02":
			return getValueByKey(BM.JBS.map, bmCode);
		case "03":
			return getValueByKey(BM.SSS.map, bmCode);
		case "04":
			return getValueByKey(BM.SXS.map, bmCode);
		case "05":
			return getValueByKey(BM.YCBS.map, bmCode);
		case "06":
			return getValueByKey(BM.WSS.map, bmCode);
		case "07":
			return getValueByKey(BM.JZJBS_FQ.map, bmCode);
		case "08":
			return getValueByKey(BM.JZJBS_MQ.map, bmCode);
		case "09":
			return getValueByKey(BM.JZJBS_XDJM.map, bmCode);
		case "10":
			return getValueByKey(BM.JZJBS_ZN.map, bmCode);
		case "11":
			return getValueByKey(BM.CJZK.map, bmCode);
		case "12":
			return getValueByKey(BM.BLS.map, bmCode);
		default:
			break;
		}
		return "";
	}

	private static String getKeyByValue(LinkedHashMap<String, String> map,
			String value) {
		Iterator iter = map.entrySet().iterator();
		while (iter.hasNext()) {
			Map.Entry entry = (Map.Entry) iter.next();
			Object key = entry.getKey();
			Object val = entry.getValue();
			if (val.equals(value)) {
				return (String) key;
			}
		}
		return "";
	}

	private static String getValueByKey(LinkedHashMap<String, String> map,
			String key) {
		Iterator iter = map.entrySet().iterator();
		while (iter.hasNext()) {
			Map.Entry entry = (Map.Entry) iter.next();
			Object k = entry.getKey();
			Object val = entry.getValue();
			if (k.equals(key)) {
				return (String) val;
			}
		}
		return "";
	}

	/***
	 * 观测方法
	 * 
	 * @author geshenjibi
	 * 
	 */
	public static class GCFF {
		public static final String[] names = new String[] { "问询", "体格检查",
				"医学检验", "病理", "影像检查" };

		public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
		static {
			map.put("01", "问询");
			map.put("02", "体格检查");
			map.put("03", "医学检验");
			map.put("04", "病理");
			map.put("05", "影像检查");
		}
	}

	/***
	 * 转归情况
	 * 
	 * @author geshenjibi
	 * 
	 */
	public static class ZGQK {
		public static final String[] names = new String[] { "痊愈", "好转", "未愈",
				"死亡", "其他" };

		public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
		static {
			map.put("1", "痊愈");
			map.put("2", "好转");
			map.put("3", "未愈");
			map.put("4", "死亡");
			map.put("5", "其他");
		}
	}

	/***
	 * 编码
	 * 
	 * @author geshenjibi
	 * 
	 */
	public static class BM {
		/**
		 * 、药物过敏史。
		 * */
		public static class YWGMS {
			public static final String[] items = new String[] { "无药物过敏史",
					"青霉素", "磺胺", "链霉素", "其他" };

			public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
			static {
				map.put("0101", "无药物过敏史");
				map.put("0102", "青霉素");
				map.put("0103", "磺胺");
				map.put("0104", "链霉素");
				map.put("0109", "其他");
			}
		}

		/**
		 * 、暴露史
		 * */
		public static class BLS {
			public static final String[] items = new String[] { "无暴露史", "化学品",
					"毒物", "射线" };

			public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
			static {
				map.put("1201", "无暴露史");
				map.put("1202", "化学品");
				map.put("1203", "毒物");
				map.put("1204", "射线");
			}
		}

		/**
		 * 疾病史
		 * */
		public static class JBS {
			public static final String[] items = new String[] { "无疾病史", "高血压",
					"糖尿病", "冠心病", "慢性阻塞性肺疾病", "恶性肿瘤", "脑卒中", "重性精神疾病", "结核病",
					"肝脏疾病", "先天畸形", "职业病", "肾脏疾病", "贫血", "其他法定传染病", "其他" };

			public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
			static {
				map.put("0201", "无疾病史");
				map.put("0202", "高血压");
				map.put("0203", "糖尿病");
				map.put("0204", "冠心病");
				map.put("0205", "慢性阻塞性肺疾病");
				map.put("0206", "恶性肿瘤");
				map.put("0207", "脑卒中");
				map.put("0208", "重性精神疾病");
				map.put("0209", "结核病");
				map.put("0210", "肝脏疾病");
				map.put("0211", "先天畸形");
				map.put("0212", "职业病");
				map.put("0213", "肾脏疾病");
				map.put("0214", "贫血");
				map.put("0298", "其他法定传染病");
				map.put("0299", "其他");
			}
		}

		/**
		 * 手术史
		 * */
		public static class SSS {
			public static final String[] items = new String[] { "无手术史", "有手术史" };

			public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
			static {
				map.put("0301", "无手术史");
				map.put("0302", "有手术史");
			}
		}

		/**
		 * 外伤史
		 * */
		public static class WSS {
			public static final String[] items = new String[] { "无外伤史", "有外伤史" };

			public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
			static {
				map.put("0601", "无外伤史");
				map.put("0602", "有外伤史");
			}
		}

		/**
		 * 输血史
		 * */
		public static class SXS {
			public static final String[] items = new String[] { "无输血史", "有输血史" };

			public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
			static {
				map.put("0401", "无输血史");
				map.put("0402", "有输血史");
			}
		}

		/**
		 * 父亲
		 * */
		public static class JZJBS_FQ {
			public static final String[] items = new String[] { "无父亲疾病史",
					"高血压", "糖尿病", "冠心病", "慢性阻塞性肺疾病", "恶性肿瘤", "脑卒中", "重性精神疾病",
					"结核病", "肝炎", "先天畸形", "其他" };

			public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
			static {
				map.put("0701", "无父亲疾病史");
				map.put("0702", "高血压");
				map.put("0703", "糖尿病");
				map.put("0704", "冠心病");
				map.put("0705", "慢性阻塞性肺疾病");
				map.put("0706", "恶性肿瘤");
				map.put("0707", "脑卒中");
				map.put("0708", "重性精神疾病");
				map.put("0709", "结核病");
				map.put("0710", "肝炎");
				map.put("0711", "先天畸形");
				map.put("0799", "其他");
			}
		}

		/**
		 * 母亲
		 * */
		public static class JZJBS_MQ {
			public static final String[] items = new String[] { "无母亲疾病史",
					"高血压", "糖尿病", "冠心病", "慢性阻塞性肺疾病", "恶性肿瘤", "脑卒中", "重性精神疾病",
					"结核病", "肝炎", "先天畸形", "其他" };

			public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
			static {
				map.put("0801", "无母亲疾病史");
				map.put("0802", "高血压");
				map.put("0803", "糖尿病");
				map.put("0804", "冠心病");
				map.put("0805", "慢性阻塞性肺疾病");
				map.put("0806", "恶性肿瘤");
				map.put("0807", "脑卒中");
				map.put("0808", "重性精神疾病");
				map.put("0809", "结核病");
				map.put("0810", "肝炎");
				map.put("0811", "先天畸形");
				map.put("0899", "其他");
			}
		}

		/**
		 * 兄弟姐妹
		 * */
		public static class JZJBS_XDJM {
			public static final String[] items = new String[] { "无兄弟姐妹疾病史",
					"高血压", "糖尿病", "冠心病", "慢性阻塞性肺疾病", "恶性肿瘤", "脑卒中", "重性精神疾病",
					"结核病", "肝炎", "先天畸形", "其他" };

			public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
			static {
				map.put("0901", "无兄弟姐妹疾病史");
				map.put("0902", "高血压");
				map.put("0903", "糖尿病");
				map.put("0904", "冠心病");
				map.put("0905", "慢性阻塞性肺疾病");
				map.put("0906", "恶性肿瘤");
				map.put("0907", "脑卒中");
				map.put("0908", "重性精神疾病");
				map.put("0909", "结核病");
				map.put("0910", "肝炎");
				map.put("0911", "先天畸形");
				map.put("0999", "其他");
			}
		}

		/**
		 * 子女
		 * */
		public static class JZJBS_ZN {
			public static final String[] items = new String[] { "无子女疾病史",
					"高血压", "糖尿病", "冠心病", "慢性阻塞性肺疾病", "恶性肿瘤", "脑卒中", "重性精神疾病",
					"结核病", "肝炎", "先天畸形", "其他" };

			public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
			static {
				map.put("1001", "无子女疾病史");
				map.put("1002", "高血压");
				map.put("1003", "糖尿病");
				map.put("1004", "冠心病");
				map.put("1005", "慢性阻塞性肺疾病");
				map.put("1006", "恶性肿瘤");
				map.put("1007", "脑卒中");
				map.put("1008", "重性精神疾病");
				map.put("1009", "结核病");
				map.put("1010", "肝炎");
				map.put("1011", "先天畸形");
				map.put("1099", "其他");
			}
		}

		/**
		 * 遗传病史
		 * */
		public static class YCBS {
			public static final String[] items = new String[] { "无遗传病史",
					"有遗传病史" };

			public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
			static {
				map.put("0501", "无遗传病史");
				map.put("0502", "有遗传病史");
			}
		}

		/**
		 * */
		public static class CJZK {
			public static final String[] items = new String[] { "无残疾", "视力残疾",
					"听力残疾 ", "言语残疾", "肢体残疾", "智力残疾", "精神残疾", "孤独症儿童", "脑瘫儿童",
					"其他残疾" };

			public static final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
			static {
				map.put("1101", "无残疾");
				map.put("1102", "视力残疾");
				map.put("1103", "听力残疾 ");
				map.put("1104", "言语残疾");
				map.put("1105", "肢体残疾");
				map.put("1106", "智力残疾");
				map.put("1107", "精神残疾");
				map.put("1108", "孤独症儿童");
				map.put("1109", "脑瘫儿童");
				map.put("1199", "其他残疾");
			}
		}

	}
}
